﻿using System;
using System.Text.RegularExpressions;
using Assist;
using Autodesk.Revit.DB;
using EvacuationWidth.Properties;
using YJKRevitCode.ElmentSearchUtility.LinkDocumentSuite;
using ModelCheckUtility.ModelLayer;

namespace EvacuationWidth.ModelLayer
{
	public class DoorPacker_EvacuationWidth : BaseDoorPacker
	{
		internal bool IfIsActingDoor
		{
			get
			{
				return this.m_bIfIsActingDoor;
			}
			private set
			{
				this.m_bIfIsActingDoor = value;
			}
		}

		public double UseDoorWidth
		{
			get
			{
				return this.m_dUseDoorWidth;
			}
			private set
			{
				this.m_dUseDoorWidth = value;
			}
		}

		public bool IfGetWidthSucess
		{
			get
			{
				return this.m_bIfGetWidthSucess;
			}
			private set
			{
				this.m_bIfGetWidthSucess = value;
			}
		}

		public DoorPacker_EvacuationWidth(FamilyInstance thisDoor, RevitLinkInstance useLinkInstance = null, ElementGeometryPacker tempGeometryPacker = null) : base(thisDoor, useLinkInstance, tempGeometryPacker)
		{
			this.IfGetWidthSucess = this.TryGetDoorWidth(out this.m_dUseDoorWidth);
			if (this.IfGetWidthSucess)
			{
				this.UseDoorWidth = AssistFunc.feetToMM(this.UseDoorWidth) / 1000.0;
			}
			if (Regex.IsMatch(base.FamilyName, Resources.Str_KeyNameOfActingDoor))
			{
				this.IfIsActingDoor = true;
			}
		}

		private bool TryGetDoorWidth(out double width)
		{
			width = 0.0;
			FamilySymbol symbol = base.ThisDoor.Symbol;
			Parameter parameter = symbol.get_Parameter((BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), Resources.Str_WidthParam));
            if (parameter == null || (int)parameter.StorageType != 2)
			{
				return false;
			}
			width = parameter.AsDouble();
			return true;
		}

		private bool m_bIfIsActingDoor;

		private double m_dUseDoorWidth;

		private bool m_bIfGetWidthSucess;
	}
}
